<?php

use Johnm\Probackend\Former\Facades\Former;

$edit_form_content = '<div class="text-center modal-frontdrop"><i class="icon-spinner3 spin block-inner"></i></div>';
$edit_form_content .= '<div class="col-sm-4">';
$edit_form_content .= '<div class="fileinput fileinput-new" data-provides="fileinput">';
$edit_form_content .= '<div class="fileinput-preview thumbnail thumbnail-boxed" style="width: 152px; height: 152px;"></div>';
$edit_form_content .= '<div class="row with-padding" style="padding-top: 0">';
$edit_form_content .= '<span style="width:100%" class="col-sm-6 btn btn-primary btn-avatar btn-file">';
$edit_form_content .= '<span class="fileinput-new">Select image</span>';
$edit_form_content .= '<span class="fileinput-exists ">Change</span>';
$edit_form_content .= '<input type="file" name="avatar-files"></span>';
$edit_form_content .= '<a href="#" class="btn btn-default fileinput-exists col-sm-6" data-dismiss="fileinput">Remove</a>';
$edit_form_content .= '</div></div></div>';
$edit_form_content .='<div class="col-sm-8">';

$edit_form_content .= '<input type="hidden" name="avatar">';

$edit_form_content .= Former::text("firstname")
        ->label(Lang::get("probackend::administrator_user.model_user_firstname"))
        ->maxlength(255)
        ->value($user->first_name)
        ->required();

$edit_form_content .= Former::text("lastname")
        ->label(Lang::get("probackend::administrator_user.model_user_lastname"))
        ->maxlength(255)
        ->value($user->last_name)
        ->required();

$edit_form_content .= Former::text("mobile")
        ->label(Lang::get("probackend::administrator_user.model_user_mobile"))
        ->maxlength(20)
        ->value($user->mobile)
        ->required();


$edit_form_content .='</div>';

$edit_form_content .='<div class="col-sm-12">';

$edit_form_content .= Former::email("email")
        ->label(Lang::get("probackend::administrator_user.model_user_email"))
        ->maxlength(255)
        ->value($user->email)
        ->required();

$edit_form_content .= Former::text("address")
        ->label(Lang::get("probackend::administrator_user.model_user_address"))
        ->maxlength(20)
        ->value($user->address)
        ->required();
$edit_form_content .='</div>';
$edit_form_content .='<div class="clearfix"></div>';


$isSU = $user->su==1?"checked":"";
$edit_form_content .= '<div class="with-padding">';
$edit_form_content .= '<label class="checkbox-inline checkbox-danger">';
$edit_form_content .= '<span class="checked"><input '.$isSU.' type="checkbox" name="su" value="1" class="styled"></span>';
$edit_form_content .= 'Super Admin</label>';
$edit_form_content .= "<BR>";

$cgroups = array();
foreach ($user->getGroups() as $group) {
    $cgroups[] = $group->id;
}

foreach ($groups as $group) {
    $isChecked = in_array($group->id, $cgroups) ? "checked" : "";
    $edit_form_content .= '';
    $edit_form_content .= '<label class="checkbox-inline checkbox-info">';
    $edit_form_content .= '<span class="checked"><input ' . $isChecked . ' type="checkbox" name="groups[]" value="' . $group->id . '" class="styled"></span>';
    $edit_form_content .= $group->title . '</label>';
    $edit_form_content .= "<BR>";
}
$edit_form_content .= "</div>";

$edit_form_content .= '<script>';
$edit_form_content .= "$('.fileinput').on('change.bs.fileinput',function(){    
    $('.fileinput-preview > img')
        .cropbox({width: 142, height: 142, zoom: 100})
        .on('cropbox', function (event, results, img) {    
            $('input[name=\"avatar\"]').val(img.getDataURL());
        });    
    $('.btn-file').removeAttr('style');
    $('.fileinput-exists').addClass('btn-avatar');    
});
$('.fileinput').on('clear.bs.fileinput',function(){    
    $('.btn-file').css('width','100%');
    $('input[name=\"avatar\"]').removeAttr('value');
});
    $(\".styled, .multiselect-container input\").uniform({ radioClass: 'choice', selectAutoWidth: false });
    $('#crub-edit-model-form').attr('action',MODULE_URL+'" . $user->id . "');
";

$edit_form_content .= '</script>';

echo $edit_form_content;
